/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.ugent.medirem.persistence.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;

/**
 * Patient Entity
 * An entity with all data concerning a real life patient
 * 
 * @author Thomas Roelens
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Patient.FindAll",
    query = "SELECT p FROM Patient p"),
    @NamedQuery(name = "Patient.FindBySocialSecurityNumber",
    query = "SELECT p FROM Patient p WHERE p.socialSecurityNr = :number"),
    @NamedQuery(name = "Patient.GetId",
    query = "SELECT p.id FROM Patient p WHERE p.username = :username")
})
public class Patient extends Account implements Serializable {

    private static final String ROLE = "patient";
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date birthdate;
    private String bloodgroup;
    private String socialSecurityNr;
    @OneToMany
    private List<Prescription> prescriptions;
    @OneToMany
    private List<Measurement> measurements;
    @ManyToMany(mappedBy = "patients")
    private List<GeneralPractitioner> generalPractitioners;

    public Patient() {
        super.setRolename(ROLE);
    }

    public Patient(String username, String password, String firstname, String surname, Date birthdate, String bloodgroup) {
        super(username, password, ROLE, firstname, surname);
        this.birthdate = birthdate;
        this.bloodgroup = bloodgroup;
    }

    public Patient(String username, String password, String firstname, String surname, Location location, Date birthdate, String bloodgroup, String socialSecurityNr) {
        super(username, password, ROLE, firstname, surname, location);
        this.birthdate = birthdate;
        this.bloodgroup = bloodgroup;
        this.socialSecurityNr = socialSecurityNr;
    }

    /**
     * Get the value of birthdate
     *
     * @return the value of birthdate
     */
    public Date getBirthdate() {
        return birthdate;
    }

    /**
     * Set the value of birthdate
     *
     * @param birthdate new value of birthdate
     */
    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    /**
     * Get the value of bloodgroup
     *
     * @return the value of bloodgroup
     */
    public String getBloodgroup() {
        return bloodgroup;
    }

    /**
     * Set the value of bloodgroup
     *
     * @param bloodgroup new value of bloodgroup
     */
    public void setBloodgroup(String bloodgroup) {
        this.bloodgroup = bloodgroup;
    }

    /**
     * Get the value of measurements
     *
     * @return the value of measurements
     */
    public List<Measurement> getMeasurements() {
        return measurements;
    }

    /**
     * Set the value of measurements
     *
     * @param measurements new value of measurements
     */
    public void setMeasurements(List<Measurement> measurements) {
        this.measurements = measurements;
    }

    public void addMeasurement(Measurement measurement) {
        this.measurements.add(measurement);
    }

    public void removeMeasurement(Measurement measurement) {
        this.measurements.remove(measurement);
    }

    /**
     * Get the value of socialSecurityNr
     *
     * @return the value of socialSecurityNr
     */
    public String getSocialSecurityNr() {
        return socialSecurityNr;
    }

    /**
     * Set the value of socialSecurityNr
     *
     * @param socialSecurityNr new value of socialSecurityNr
     */
    public void setSocialSecurityNr(String socialSecurityNr) {
        this.socialSecurityNr = socialSecurityNr;
    }

    /**
     * Get the value of prescriptions
     *
     * @return the value of prescriptions
     */
    public List<Prescription> getPrescriptions() {
        return prescriptions;
    }

    /**
     * Set the value of prescriptions
     *
     * @param prescriptions new value of prescriptions
     */
    public void setPrescriptions(List<Prescription> prescriptions) {
        this.prescriptions = prescriptions;
    }

    public void addPrescription(Prescription prescription) {
        this.prescriptions.add(prescription);
    }

    public void removePrescription(Prescription prescription) {
        this.prescriptions.remove(prescription);
    }

    public List<GeneralPractitioner> getGeneralPractitioners() {
        return generalPractitioners;
    }

    public void setGeneralPractitioners(List<GeneralPractitioner> generalPractitioners) {
        this.generalPractitioners = generalPractitioners;
    }

    public void addGeneralPrescriptioner(GeneralPractitioner gp) {
        this.generalPractitioners.add(gp);
    }
}

